function(FindMediaSDK)
  pkg_check_modules(MFX  QUIET  mfx)
  set(MFX_LIBS "")
  if(MFX_FOUND)
     message(STATUS "MFX_LIBRARY_DIRS: ${MFX_LIBDIR}")
     include_directories (${MFX_INCLUDE_DIRS})
     #set (${libs} ${MFX_LIBS} PARENT_SCOPE)
     set(MFX_LIBRARY  "${MFX_LIBDIR}/libmfx.so")
  else()
    if(DEFINED ENV{MFX_HOME})
      message(STATUS "MediaSDK distribution found in $ENV{MFX_HOME}")
      set(MFX_HOME $ENV{MFX_HOME})
    elseif (EXISTS "/opt/intel/mediasdk")
      message(STATUS "MediaSDK distribution found in /opt/intel/mediasdk")
      set(MFX_HOME "/opt/intel/mediasdk")
    else()
      message(FATAL_ERROR "No MediaSDK distribution is found.")
    endif()
    set(MFX_INCLUDES "${MFX_HOME}/include")
    set(MFX_LIBRARY  "${MFX_HOME}/lib/lin_x64/libmfx.a")
    message(STATUS "MediaSDK include directory: ${MFX_INCLUDES}")
    message( STATUS "MediaSDK library directory: ${MFX_LIBRARY}")
    include_directories(${MFX_INCLUDES})
  endif()
  add_library(libmfx SHARED IMPORTED)
  set_property(TARGET libmfx PROPERTY IMPORTED_LOCATION ${MFX_LIBRARY})
endfunction(FindMediaSDK)
